<script lang="ts" setup>
import {ref,defineEmits} from "vue";
import $kt from "/src/components/kantboot"
import { useSettingStore } from "../storeMoudules/setting.ts";

let settingStore = useSettingStore();
let emits = defineEmits(["submit"]);

let dialogVisible = ref(false);

type RequestParam = {
  id: number,
  name: string,
}

let requestParamInit: RequestParam = {
  id: null,
  name: "",
}

let requestParam = ref<RequestParam>(
    JSON.parse(JSON.stringify(requestParamInit))
);

let init = () => {
  requestParam.value = JSON.parse(JSON.stringify(requestParamInit));
}


let save = () => {
  $kt.request.request({
    url: "/system-user-web/admin/org/save",
    method: "post",
    data: requestParam.value,
    stateSuccess: (res: any) => {
      dialogVisible.value = false;
      emits("submit");
      init();
    }
  });
};

let open = (param?: any) => {
  if (param) {
    requestParam.value = JSON.parse(JSON.stringify(param));
  }
  dialogVisible.value = true;
};

defineExpose({
  open,
});

</script>

<template>
  <el-dialog title="保存" v-model="dialogVisible"
             width="30%">
    <el-form :model="requestParam"
             label-position="top"
             label-width="80px">

      <el-form-item label="公司名称" prop="name">
        <el-input v-model="requestParam.name"></el-input>
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<style scoped>
.dialog-footer {
  text-align: right;
}
</style>